// pages/my/rushordervoucher/rushordervoucher.js
Page({
  data: {
    id: "",
    takenUserId: "",
    toggle: false,
    toggle2: false,
    fileList: [],
    imgIds: [],
    dialog_success: false,
    dialog_fail: false,
    detail: {},
    fileList2: [],
    fileList3: [],
    fileList4: [],
  },
  onLoad(options) {
    this.setData({
      id: options.id,
      takenUserId: options.userId
    });
    this.getData();
  },
  upload(e) {
    getApp().globalData.util.imgsUpload(this, e, this.data.fileList, this.data.imgIds);
  },
  delete(e) {
    let i = e.detail.index;
    let fileList = this.data.fileList;
    let imgIds = this.data.imgIds;
    fileList.splice(i, 1);
    imgIds.splice(i, 1);
    this.setData({
      fileList: fileList,
      imgIds: imgIds
    });
  },
  getData() {
    getApp().globalData.http.reDetail({
      id: this.data.id,
      takenUserId: this.data.takenUserId
    }).then(res => {
      let tmp = res.data;
      tmp.imgIds = tmp.imgIds.split(",");
      tmp.imgUrls = tmp.imgUrls.split(",");
      this.setData({
        detail: res.data,
      });
      if (res.data.reviewStatus != 0) {
        this.setData({
          fileList: !!res.data.takenHistoryVo.firstEvidenceImgIds ? res.data.takenHistoryVo.firstEvidenceImgIds.split(",") : [],
          fileList2: !!res.data.takenHistoryVo.firstReviewImgIds ? res.data.takenHistoryVo.firstReviewImgIds.split(",") : [],
          fileList3: !!res.data.takenHistoryVo.secondEvidenceImgIds ? res.data.takenHistoryVo.secondEvidenceImgIds.split(",") : [],
          fileList4: !!res.data.takenHistoryVo.secondReviewImgIds ? res.data.takenHistoryVo.secondReviewImgIds.split(",") : [],
        });
      }
      if (res.data.reviewStatus == 6) {
        this.setData({
          dialog_fail: true
        });
      }
    });
  },
  toggle() {
    this.setData({
      toggle: !this.data.toggle
    });
  },
  toggle2() {
    this.setData({
      toggle2: !this.data.toggle2
    });
  },
  submit() {
    if (this.data.imgIds.length == 0) {
      getApp().globalData.vant.toast("请上传凭证");
    } else {
      getApp().globalData.http.evidence({
        id: this.data.id,
        historyId: this.data.detail.historyId,
        reviewStatus: this.data.detail.reviewStatus,
        firstEvidenceContent: "",
        firstEvidenceImgIds: this.data.imgIds.join(",")
      }).then(res => {
        this.setData({
          dialog_success: true,
        });
      }).catch(e => {
        getApp().globalData.vant.toast.fail(!e.msg ? "失败" : e.msg);
      });
    }
  },
  successClick() {
    wx.navigateBack();
  },
  complaint() {
    wx.navigateTo({
      url: "/pages/my/complaint/complaint?id=" + this.data.id + "&historyId=" + this.data.detail.historyId + "&reviewStatus=" + this.data.detail.reviewStatus,
    });
  },
  previewImg(e) {
    let arr = e.currentTarget.dataset.img;
    let current = e.currentTarget.dataset.current;
    getApp().globalData.util.previewImage(arr, current);
  }
})